home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news!enno
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: Multiple Abstract Classes Question
- Date: 18 Jan 1996 19:48:13 GMT
- Organization: Fachbereich Informatik, TH Darmstadt
- Distribution: world
- Message-ID: <ENNO.96Jan18204813@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <1996Jan17.160425.6063@ned.cray.com>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: aztec@cray.com's message of 17 Jan 96 16:04:25 CST
-
- In article <1996Jan17.160425.6063@ned.cray.com> aztec@cray.com (Joel Garcia-Trevino {x66457 CF/DEV}) writes:
-
- Can I or is it a good idea to have multiple abstract classes to start building
- a class hierarchy?
-
- Example of the base (abstract) classes:
-
- class base_type;
-
- class base_net {
- public:
- virtual char *get_name() = 0; // Gets the name
- virtual base_type *get_type() = 0; // Gets pointer to type
- };
-
- class base_type {
- public:
- virtual char *get_type() = 0; // Gets type name
- };
-
-
- The final classes would look something like:
-
- class type;
-
- class net: public base_net {
- private:
- char *name;
- type *type_pntr;
-
- public:
- char *get_name() { ..... };
- type *get_type() { ..... };
-
- };
-
- class type: public base_type {
- private:
- char *type_name;
-
- public:
- char *get_type() { ..... };
-
- };
-
-
- Does it make sense to do it this way?
-
- The reason why I want to do this is because there will be different types
- of nets that I will need to work with. I don't know if there will be
- different types of "type" but I thought why not make them all abstract. ???
-
- In theory building parallel class-hierachies is nothing bad.
- However things become it bit uncomfortable if your compiler
- doesn't support covariant return types. In this case you can
- not have different return types for different implementations
- of a polymorphic function. Therefore '{net,bas_net} :: get_type'
- would both have to return a 'base_type' pointer which has to
- be narrowed using the old-style cast or the 'dynamic_cast'
- (or an appropriate 'emulation' of it). So your approach seems
- reasonable but can cause slightly problems with todays compilers.
- Anyway you should also take a solution using template specialization
- into consideration.
-
- Enno
-
-
-
-